# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>

_pyname=bluepy-v
pkgname=python-bluepy
pkgver=1.3.0
pkgrel=9
pkgdesc='Python module for interfacing with Bluetooth LE devices through Bluez'
url='https://github.com/IanHarvey/bluepy'
arch=('loong64' 'x86_64')
license=('GPL2')
depends=('python' 'bluez' 'glib2')
makedepends=('python-build' 'python-installer' 'python-setuptools' 'python-sphinx' 'python-wheel')
options=('!makeflags')
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/IanHarvey/bluepy/archive/v/${pkgver}.tar.gz)
sha256sums=('878e68e6d0f2823a5ebc5763e97ed887cc599120a5cc0bac577b7d655db6cd3e')
sha512sums=('817fcc44646008a4aadac39b1e9ef694fd706b4d23e2299c78084e48f804beec2e76af2701572ce76d9cf325de09e0ded539dd1ceb6ed574cb5d589045c17e37')

prepare() {
  cd ${_pyname}-${pkgver}
  sed 's|CFLAGS =|CFLAGS +=|g' -i bluepy/Makefile
  sed 's|CPPFLAGS =|CPPFLAGS +=|g' -i bluepy/Makefile
  sed 's| $(LDLIBS)| $(LDFLAGS) $(LDLIBS)|g' -i bluepy/Makefile
}

build() {
  cd ${_pyname}-${pkgver}
  python -m build --wheel --no-isolation
  make -C bluepy
  make -C docs man text SPHINXBUILD=sphinx-build
}

package() {
  cd ${_pyname}-${pkgver}

  # install
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -Dm 644 README.md docs/_build/text/*.txt -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 docs/_build/man/bluepy.1 "${pkgdir}/usr/share/man/man1/${pkgname}.1"
  install -Dm 755 bluepy/bluepy-helper -t "${pkgdir}"/usr/lib/python*/site-packages/bluepy

  # cleanup
  rm "${pkgdir}"/usr/lib/python*/site-packages/bluepy/{bluez-src.tgz,Makefile,bluepy-helper.c}
}

# vim: ts=2 sw=2 et:
